﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Windows.Forms;

namespace ConnectCsharpToMysql.objects
{
    class PartVideo
    {
        public String idPartVideo;
        public String namePartVideo;
        public String desPartVideo;
        public String partVideo;
        public String status;
        public String orders;
        public String createDate;
        public String idVideo;

        public PartVideo() { }

        public Boolean select()
        {
            String strSelectQuery = "SELECT * FROM tbpartvideo WHERE idPartVideo = " + idPartVideo;
            DataTable dataTable = new DBConnect().Select(strSelectQuery);
            if (dataTable.Rows.Count > 0)
            {
                namePartVideo = dataTable.Rows[0]["namePartVideo"].ToString();
                desPartVideo = dataTable.Rows[0]["desPartVideo"].ToString();
                partVideo = dataTable.Rows[0]["partVideo"].ToString();
                status = dataTable.Rows[0]["status"].ToString();
                orders = dataTable.Rows[0]["order"].ToString();
                createDate = dataTable.Rows[0]["createDate"].ToString();
                idVideo = dataTable.Rows[0]["idVideo"].ToString();
                return true;
            }
            else
            {
                return false;
            }
        }

        public static List<PartVideo> selectAll(String idVideo)
        {
            List<PartVideo> listPartVideo = new List<PartVideo>();
            String strSelectQuery = "SELECT * FROM tbpartvideo idVideo = " + idVideo;
            DataTable dataTable = new DBConnect().Select(strSelectQuery);
            for (int i = 0; i < dataTable.Rows.Count; i++)
            {
                PartVideo partVideo = new PartVideo();
                partVideo.idPartVideo = dataTable.Rows[0]["idPartVideo"].ToString();
                partVideo.namePartVideo = dataTable.Rows[0]["namePartVideo"].ToString();
                partVideo.desPartVideo = dataTable.Rows[0]["desPartVideo"].ToString();
                partVideo.partVideo = dataTable.Rows[0]["partVideo"].ToString();
                partVideo.status = dataTable.Rows[0]["status"].ToString();
                partVideo.orders = dataTable.Rows[0]["order"].ToString();
                partVideo.createDate = dataTable.Rows[0]["createDate"].ToString();
                partVideo.idVideo = dataTable.Rows[0]["idVideo"].ToString();
                listPartVideo.Add(partVideo);
            }
            return listPartVideo;
        }

        public Boolean insert()
        {
            String strInserQuery = "INSERT INTO tbpartvideo (namePartVideo,desPartVideo,partVideo,status,orders,createDate,idVideo) " +
                                    "VALUES(N'" + namePartVideo + "',N'" + desPartVideo + "','" + partVideo + "','" + status + "','" + orders + "','" + createDate + "','" + idVideo + "') ";
            MessageBox.Show(strInserQuery);
            return new DBConnect().Insert(strInserQuery);
        }

        public Boolean update()
        {
            String strUpdateQuery = "UPDATE tbpartvideo " +
                        "SET namePartVideo=N'" + namePartVideo + "',desPartVideo='" + desPartVideo + "',partVideo='" + partVideo + "',status='" + status + "',order='" + orders + "',createDate='" + createDate + "',idVideo='" + idVideo + "' " +
                        "WHERE idPartVideo=" + idPartVideo;
            return new DBConnect().Update(strUpdateQuery);
        }

        public Boolean delete()
        {
            String strDeleteQuery = "DELETE FROM tbpartvideo WHERE idPartVideo = " + idPartVideo;
            return new DBConnect().Delete(strDeleteQuery);
        }
    }
}
